Skip to content

[FC-0099] refactor!: consider global scope as wildcard managed by ScopeData#132

Merged
mariajgrimaldi merged 8 commits intomainfrom
MJG/global-lib-scope
Nov 5, 2025
Merged

[FC-0099] refactor!: consider global scope as wildcard managed by ScopeData#132
mariajgrimaldi merged 8 commits intomainfrom
MJG/global-lib-scope

Conversation

@mariajgrimaldi
Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi commented Oct 31, 2025

Description

This PR adds support to the global type by allowing the use of "*" as a global external_key that will be managed by the base ScopeData class with global namespace.

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Oct 31, 2025
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Oct 31, 2025

Thanks for the pull request, @mariajgrimaldi!

This repository is currently maintained by @openedx/committers-openedx-authz.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mariajgrimaldi mariajgrimaldi changed the title refactor: consider global scope wildcard when instantiating scope refactor: consider global scope as wildcard managed by ScopeData Oct 31, 2025
@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review October 31, 2025 17:19
Comment thread openedx_authz/api/data.py Outdated
Comment on lines 314 to 319
# The 'sc' namespace is used for generic scopes that aren't tied to a specific resource type.
# This base class supports:
# 1. Global scopes (external_key='*') that apply across all resource types
# 2. Custom generic scopes that don't map to specific domain objects
# Subclasses like ContentLibraryData ('lib') represent concrete resource types.
NAMESPACE: ClassVar[str] = "sc"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmtcril: remember we talked about the usage of this generic scope? I think we found one!

I was thinking of changing NAMESPACE to an empty string cause I'm not sure how descriptive is sc. What do you think?

FYI @MaferMazu @BryanttV

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did "sc" stand for?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could change it to something related to "anonymous", as if it's supposed to identify scopes that don't map to specific objects, then they are "anonymous"?

Thinking on the usage of a namespaced key, it would look something like:

"anon^*"

Otherwise if we use an empty string, it woud be like "^*" right?

Won't this cause confusion because of the "missing" namespace?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc means scope 🥲, not very explicit though. Initially was only to have base definitions for all the other scopes, but now we can use it for global scopes so it might make sense to change this namespace.

Won't this cause confusion because of the "missing" namespace?

I think it will! Considering what I said here, https://github.com/openedx/openedx-authz/pull/132/files#r2486208488, instead of anonymous, should we use global or some synonym?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think global makes the most sense, but whatever we use needs to be something that will never get a real value of the same name, right?

Copy link
Copy Markdown
Member Author

@mariajgrimaldi mariajgrimaldi Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly! What about these?

  1. global: global^* (++1 most votes)
  2. instance: instance^*

In all cases, having something like can_create_libraries in NAMESPACE^* would mean I can create any number of libraries in my Open edX instance. This only makes sense for the * external key, right? It wouldn’t make sense for a specific key or would it also apply there? If so, then maybe we won't get values with the same name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding here is that in the case of the can_create_libraries permission, global^* Would mean that it applies to anything, not only libraries, but in practice can_create_libraries will only be evaluated on lib objects.

But, if at some point we add some more generic permissions, like can_create, that could apply that more than one domain object, then we could define more specific things, like global^*:DemoX:CSPROB, that would apply on anything on the org DemoX that is called CSPROB (courses, libs, etc). But this is a whole different level of complexity that I don't think we need now.

Copy link
Copy Markdown
Member Author

@mariajgrimaldi mariajgrimaldi Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing with can_create_libraries is that we can't actually evaluate it with a concrete library, but only against the instance (not sure how to call it) so it could be similar to can_create but only checked in context of libraries - hopefully I'm not getting all of this mixed up (so please correct me if I'm wrong!) 😅

that would apply on anything on the org DemoX that is called CSPROB (courses, libs, etc). But this is a whole different level of complexity that I don't think we need now.

I totally agree. Do you think global^*:DemoX:CSPROB wouldn't work for that can_create case? Oh I understand now! We should consider also cases without the *!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you are right, for can_create_libraries it doesn't make sense to specify a concrete library, so global makes sense there. It would make sense for something like can_edit_library instead.

Comment thread openedx_authz/api/data.py Outdated
# an external_key to mean generic scope which maps to base ScopeData class.
# The only remaining issue is that internally the namespace key used in policies will be
# The generic scope namespace (sc^*), so we need to handle that case here.
if kwargs.get("external_key") == GENERIC_SCOPE_WILDCARD:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic or global?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a question on naming, I think global is clearer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially used generic scope cause this scope can be specialized into other scopes: content libraries, courses... But this might be too ambiguous. It might make sense making it global when not specialized?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global makes more sense to me 👍

Comment thread openedx_authz/api/data.py Outdated
# an external_key to mean generic scope which maps to base ScopeData class.
# The only remaining issue is that internally the namespace key used in policies will be
# The generic scope namespace (sc^*), so we need to handle that case here.
if kwargs.get("external_key") == GENERIC_SCOPE_WILDCARD:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a question on naming, I think global is clearer.

Comment thread openedx_authz/api/data.py Outdated
Comment on lines 314 to 319
# The 'sc' namespace is used for generic scopes that aren't tied to a specific resource type.
# This base class supports:
# 1. Global scopes (external_key='*') that apply across all resource types
# 2. Custom generic scopes that don't map to specific domain objects
# Subclasses like ContentLibraryData ('lib') represent concrete resource types.
NAMESPACE: ClassVar[str] = "sc"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did "sc" stand for?

Comment thread openedx_authz/api/data.py Outdated
Comment on lines 314 to 319
# The 'sc' namespace is used for generic scopes that aren't tied to a specific resource type.
# This base class supports:
# 1. Global scopes (external_key='*') that apply across all resource types
# 2. Custom generic scopes that don't map to specific domain objects
# Subclasses like ContentLibraryData ('lib') represent concrete resource types.
NAMESPACE: ClassVar[str] = "sc"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could change it to something related to "anonymous", as if it's supposed to identify scopes that don't map to specific objects, then they are "anonymous"?

Thinking on the usage of a namespaced key, it would look something like:

"anon^*"

Otherwise if we use an empty string, it woud be like "^*" right?

Won't this cause confusion because of the "missing" namespace?

Comment thread openedx_authz/api/data.py Outdated
@mariajgrimaldi mariajgrimaldi changed the title refactor: consider global scope as wildcard managed by ScopeData [FC-0099] refactor: consider global scope as wildcard managed by ScopeData Nov 3, 2025
@mariajgrimaldi mariajgrimaldi moved this to Ready for review in RBAC AuthZ Board Nov 3, 2025
@mariajgrimaldi
Copy link
Copy Markdown
Member Author

@MaferMazu: can you confirm this version still works for you?

@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Nov 4, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 4, 2025
Comment thread openedx_authz/api/data.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to GLOBAL_SCOPE_WILDCARD?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks for the suggestion :)

Copy link
Copy Markdown
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go after the change of GENERIC_SCOPE_WILDCARD to GLOBAL_SCOPE_WILDCARD.

Copy link
Copy Markdown
Contributor

@MaferMazu MaferMazu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @mariajgrimaldi, they work as expected <3

@mariajgrimaldi mariajgrimaldi changed the title [FC-0099] refactor: consider global scope as wildcard managed by ScopeData [FC-0099] feat: consider global scope as wildcard managed by ScopeData Nov 5, 2025
@mariajgrimaldi mariajgrimaldi changed the title [FC-0099] feat: consider global scope as wildcard managed by ScopeData [FC-0099] refactor!: consider global scope as wildcard managed by ScopeData Nov 5, 2025
@mariajgrimaldi mariajgrimaldi merged commit b9414ed into main Nov 5, 2025
14 checks passed
@mariajgrimaldi mariajgrimaldi deleted the MJG/global-lib-scope branch November 5, 2025 12:14
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in RBAC AuthZ Board Nov 5, 2025
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Nov 5, 2025
@mariajgrimaldi mariajgrimaldi mentioned this pull request Mar 17, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project
Status: Done

Development

Successfully merging this pull request may close these issues.

Bug: I need to check if someone has permissions globally using openedx-authz

6 participants